package com.wuyan.locationdog.view

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.text.InputType
import android.view.View
import android.view.WindowManager
import android.widget.EditText
import android.widget.TextView
import com.arcsoft.commonbase.R


class InputDialog(
    context: Context,
    var title: String? = null,
    var hintText: String? = null,
    var showText: String? = null,
    var sureCallback: (String) -> Unit
) :
    Dialog(context, R.style.CommonDialog) {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(com.wuyan.locationdog.R.layout.dialog_input)
        setCanceledOnTouchOutside(false)
        //设置黑暗度
        window?.apply {
            attributes.dimAmount = 0.3f
            addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
        }
        val tv_title = findViewById<TextView>(R.id.tv_title)
        val etInput = findViewById<EditText>(com.wuyan.locationdog.R.id.etInput)

        title?.apply { tv_title.text = this }
        hintText?.apply { etInput.setHint(this) }
        showText?.apply { etInput.setText(this) }

        findViewById<View>(R.id.btn_sure).setOnClickListener {
            sureCallback.invoke(etInput.text.toString())
        }
        findViewById<View>(R.id.btnCancel).setOnClickListener {
            dismiss()
        }
    }


    fun setNum(num: Int) {
        val etInput = findViewById<EditText>(com.wuyan.locationdog.R.id.etInput)
        etInput.inputType = InputType.TYPE_CLASS_NUMBER
        etInput.setText(num.toString())
    }
    fun setInputType() {
        val etInput = findViewById<EditText>(com.wuyan.locationdog.R.id.etInput)
        etInput.inputType = InputType.TYPE_CLASS_NUMBER
    }
    fun setText(text: String): Dialog {
        val etInput = findViewById<EditText>(com.wuyan.locationdog.R.id.etInput)
        etInput.setText(text.toString())

        return this
    }


}



